Skip to content

Fix c_int to u32 type mismatch in c-wrapper-crate FFI wrapper#38

Merged
XuJiandong merged 5 commits into
nervosnetwork:mainfrom
Xcodes-chain:main
Feb 28, 2026
Merged

Fix c_int to u32 type mismatch in c-wrapper-crate FFI wrapper#38
XuJiandong merged 5 commits into
nervosnetwork:mainfrom
Xcodes-chain:main

Conversation

@Xcodes-chain

Copy link
Copy Markdown
Contributor

value() returns u32 but wraps bar() which returns c_int (i32). The as u32 cast silently converts negative return values — a -1 error code becomes 4294967295. Since this is a scaffold template, downstream contracts inherit the bug.

  • Changed value() return type from u32 to i32 to match the FFI signature
  • Removed the lossy as u32 cast
// Before
pub fn value() -> u32 {
    (unsafe { bar() }) as u32
}

// After
pub fn value() -> i32 {
    unsafe { bar() }
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Xcodes-chain and others added 5 commits November 13, 2024 10:43
@XuJiandong XuJiandong merged commit a15a501 into nervosnetwork:main Feb 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants